package org.springcloud.wisdom.spring_01_canteen.mall;

import org.springcloud.wisdom.spring_01_canteen.common.bean.Page;
import org.springcloud.wisdom.spring_01_canteen.login.entity.Mall;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MallService {
    @Autowired
    MallDao mallDao;
    public Page<Mall> getOnrePage(int pageNum, int pageSize, String canteen){
        //计算起始位置
        int start=(pageNum-1)*pageSize;
        //获取分页的数据
        List<Mall> list=mallDao.mall(start,pageSize,canteen);
        //获取总条目数
        int total=mallDao.countMall(canteen);
        //计算总页数
        int pages =(int) (total % pageSize == 0 ? total / pageSize : total / pageSize + 1);
        //创建分页对象
        Page<Mall> page=new Page<>();
        page.setRecords(list);
        page.setTotal(total);
        page.setPages(pages);
        page.setCurrent(pageNum);
        page.setSize(pageSize);
        return page;
    }

}
